import time

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Chrome()  # 设置浏览器驱动
driver.get("https://staging-abp.autodatas.net/bp/login")  # 登录Darwin_Staging环境网址
driver.maximize_window()  # 浏览器窗口最大化
driver.implicitly_wait(60)  # 设置隐形等待


# 语言切换
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div[3]/div[1]").click()  # 点击语言切换按钮
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div[3]/div[2]/div[2]").click()  # 点击切换到中文
time.sleep(6)

# 登录Darwin系统
driver.find_element(By.XPATH,"/html/body/div/div/div/div[4]/div/form/input").clear()  # 清除邮箱
driver.find_element(By.XPATH,"/html/body/div/div/div/div[4]/div/form/input").send_keys("liujiakang@autodatas.net")
# 输入邮箱

driver.find_element(By.XPATH,"/html/body/div/div/div/div[4]/div/form/div/input").clear()  # 清除密码
driver.find_element(By.XPATH,"/html/body/div/div/div/div[4]/div/form/div/input").send_keys("Ljk@123#")  # 输入密码
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div[4]/div/button").click()  # 点击登录
time.sleep(1)

# 导航栏（布局设置）
hover_element = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/div[2]/div/div[5]/span")  # 鼠标悬停在布局设置
action = ActionChains(driver)
action.move_to_element(hover_element).perform()
time.sleep(1)

# dropdown_element = driver.find_element_by_id("/html/body/div[5]/div/div/div/ul/li/ul/li[2]/span")
# 点击图标设置（大图标）
# action.move_to_element(dropdown_element).click().perform()

# driver.find_element(By.XPATH,"/html/body/div[5]/div/div/div/ul/li[2]/ul/li[1]/span").click()

time.sleep(2)

# 车辆拆解
driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[1]").click()  # 点击车辆拆解模块图标

# 点击筛选的车辆品牌名称
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div[3]/div[2]/div/div[1]/div/div[1]/div/div/"
                             "span[1]/input").click()
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div/ul[1]/li[2]/div[1]").click()  # 点击品牌首字母
time.sleep(2)

driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div/ul[2]/li[9]/div").click()  # 点击车辆品牌
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div[3]/div[2]/div/div[3]/div/div[3]").click()
# 点击车辆图标

time.sleep(2)

# 车辆拆解-车辆详情
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[3]/div[1]/div[3]/"
                             "div/div/div/div/span[2]").click()  # 收起整车节点
time.sleep(1)
# BOM一键展开/收起
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[3]/div[1]/div[3]/"
                             "div/div/div/div[1]/span[3]/span/div/div/div").click()  # 展开BOM节点
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[3]/div[1]/div[3]/"
                             "div/div/div/div[1]/span[3]/span/div/div/div").click()  # 收起BOM节点

time.sleep(1)

# 查询BOM零件名称
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[2]/span/span/span/"
                             "span[1]/input").clear()  # 清除关键词

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[2]/span/span/span/"
                             "span[1]/input").send_keys("车门总成")  # 输入关键词
time.sleep(2)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[2]/span/span/span/"
                             "span[2]/button").click()  # 点击查询关键词按钮
time.sleep(2)

# 进入BOM零部件节点
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[3]/div[1]/div[3]/"
                             "div/div/div/div[6]/span[3]/span/div/div/span").click()  # 点击“车门总成”节点

time.sleep(5)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/div/"
                             "div[2]/div").click()  # 点击“详情”页签
time.sleep(5)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/div/"
                             "div[5]/div").click()  # 点击“紧固件”页签
time.sleep(5)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/div/"
                             "div[4]/div").click()  # 点击“零件细节”页签
time.sleep(5)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/div/"
                             "div[6]/div").click()  # 点击“3D”页签
time.sleep(30)

# 零部件图片
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/"
                             "div/div[1]/div").click()  # 点击零部件图片页签
time.sleep(5)

# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
#                              "div/div[2]/div/div[1]/div[2]/div/div[1]/div[1]").click()  # 点击零部件图片-全局预览图片
# time.sleep(6)
#
# photo_element = driver.find_element_by_id("/html/body/div[5]/div/div/div/ul/li/ul/li[2]/span")
# action.move_to_element(photo_element).click().perform()  # 退出图片预览
# time.sleep(5)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
                             "div/div[1]/div[1]/div/div[2]/div").click()  # 点击零部件图片-细节
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
                             "div/div[1]/div[1]/div/div[3]/div").click()  # 点击零部件图片-测量
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
                             "div/div[1]/div[1]/div/div[4]/div").click()  # 点击零部件图片-拆解
time.sleep(1)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
                             "div/div[1]/div[1]/div/div[5]/div").click()  # 点击零部件图片-全家福
time.sleep(1)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/div/div[1]/"
                             "div/div[1]/div[1]/div/div[6]/div").click()  # 点击零部件图片-插头
time.sleep(1)

driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[1]/div[1]/div/"
                             "div[7]/div").click()  # 点击爆炸图页签
time.sleep(1)

# 点击收藏/取消收藏按钮
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[1]/div[2]/div[3]/"
                             "button/div").click()  # 收藏
time.sleep(5)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[1]/div[2]/div[3]/"
                             "button/div").click()  # 取消收藏
time.sleep(5)

# 导出
element = driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[2]/div[2]/"
                                       "div[2]/button")
action.move_to_element(element).perform()
time.sleep(6)
driver.find_element(By.XPATH,"/html/body/div[4]/div/div/div/div[2]/div/div/div").click()
time.sleep(2)
#
# # 点击对比按钮
# link = driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[1]/div[2]/"
#                                     "div[1]/button")
# # ActionChains(driver).move_to_element(link).perform()
# link.click()
# window_handles = driver.window_handles
# driver.switch_to.window(window_handles[1])
# time.sleep(6)
#
# # driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/div[3]/"
# #                              "div/span")
# # time.sleep(1)
# # 选择车辆（添加对比车辆）
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[1]").click()
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[2]").click()
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[3]").click()
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[4]").click()
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[5]").click()
# # driver.find_element(By.XPATH,"/html/body/div[3]/div/div/div/div[2]/div/div/ul/li[6]").click()
# # time.sleep(1)
# # 隐藏相同
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/div[1]/p[3]"
#                              "/label[1]/span[1]").click()
# time.sleep(2)
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/div[1]/p[3]"
#                              "/label[1]/span[1]").click()
#
# # 亮度不同
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/div[1]/p[3]"
#                              "/label[2]/span[1]").click()
# time.sleep(2)
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/div[1]/p[3]"
#                              "/label[2]/span[1]").click()
#
# # 点击车辆对比导出按钮
element = driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div/div/div[1]/"
                                       "div[1]/p[1]/span[2]")
# ActionChains(driver).move_to_element(element).perform()
# time.sleep(5)
# driver.close()
# # 当前BOM信息对比导出
# # driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div[2]/div/div[1]").click()
# # 当前BOM重量对比导出
# # driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div[2]/div/div[2]").click()
# # driver.switch_to.window(window_handles[0])
#
# # 点击3D按钮，进入3D点云模块
# # window_handles = driver.window_handles
# # driver.switch_to.window(window_handles[0])
# # driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[1]/div[2]/div[4]").\
# #     click()
# # time.sleep(8)
# # window_handles = driver.window_handles
# # driver.switch_to.window(window_handles[1])
# # time.sleep(6)
# # driver.close()
#
# # 返回车辆拆解-车辆列表
# window_handles = driver.window_handles
# driver.switch_to.window(window_handles[0])
# driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[1]").click()
# time.sleep(1)
#
# # 部件拆解-电池包-车辆列表
# element1 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element1).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-电驱-车辆列表
# element2 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element2).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-电子&电气-车辆列表
# element3 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element3).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-白车身-车辆列表
# element4 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element4).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-底盘-车辆列表
# element5 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element5).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-座椅-车辆列表
# element6 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element6).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-灯具-车辆列表
# element7 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element7).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-热管理-车辆列表
# element8 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element8).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 部件拆解-零部件-车辆列表
# element9 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[2]/div")
# ActionChains(driver).move_to_element(element9).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# #性能参数-总布置-车辆列表
# element10 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[3]/div")
# ActionChains(driver).move_to_element(element10).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# #性能参数-性能试验-车辆列表
# element11 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[3]/div")
# ActionChains(driver).move_to_element(element11).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 2D断面-车辆列表
# driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[4]").click()
# time.sleep(2)
# # 进入2D详情页
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div[5]/div[3]/div[2]").\
#     click()
# # 展开树结构
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[2]/div[1]/div[3]/"
#                              "div/div/div/div[1]/span[2]/span").click()
# # 查看断面图
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[1]/div[2]/div[1]/div[3]/"
#                              "div/div/div/div[2]/span[3]/span").click()
# time.sleep(4)
# # window_handles = driver.window_handles
# # driver.switch_to.window(window_handles[1])
# # time.sleep(6)
# # driver.close()
#
# # # 点击 整车外饰主断面 页签
# # window_handles = driver.window_handles
# # driver.switch_to.window(window_handles[0])
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[3]/div[1]/div[1]/"
#                              "div/div[2]/div").click()
# time.sleep(2)
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[3]/div[1]/div[1]/div"
#                              "/div[3]/div").click()
# time.sleep(2)
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/section/div[3]/div[1]/div[1]/div/"
#                              "div[4]/div").click()
# time.sleep(2)
#
# # 3D点云-车辆列表
# driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[5]").click()
# time.sleep(1)
#
# # 3D点云-车辆详情
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[2]/div[2]/div[3]").click()
# time.sleep(30)
#
# # BOM一键展开/收起
# # driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[2]/"
# #                              "div/div[3]/div/div/div/div[1]/span[4]/span/span/div[2]/div[2]/i/svg").click()
# # time.sleep(30)
# # driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[2]/"
# #                              "div/div[3]/div/div/div/div[1]/span[4]/span/span/div[2]/div[2]").click()
# # time.sleep(30)
#
# # 查询BOM节点名称
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[1]/"
#                              "div[2]/div/input").clear()
# time.sleep(6)
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[1]/"
#                              "div[2]/div/input").send_keys("主驾车门焊接总成")
# time.sleep(1)
#
# # 取消已选择点云节点
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[2]/"
#                              "div/div[3]/div/div/div/div[4]/span[3]").click()
# time.sleep(1)
# # 选择BOM节点
# driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div[1]/div/div[4]/div[1]/div[2]"
#                              "/div/div[3]/div/div/div/div[5]/span[3]").click()
# time.sleep(1)
# # driver.find_element(By.XPATH,"/html/body/div[1]/div/div/section/div[2]/div/div[2]/div/div/div[2]/div[4]/div[1]/div[2]/"
# #                              "div/div[3]/div/div/div/div[5]/span[4]/span/span/div[1]/div/svg").click()
# # time.sleep(1)
#
# # 汽车视界-汽车展览-车辆列表
# element12 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[6]/div")
# ActionChains(driver).move_to_element(element12).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 汽车视界-HMI3.0-车辆列表
# element13 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[6]/div")
# ActionChains(driver).move_to_element(element13).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 成本分析-车辆成本分析-车辆列表
# element14 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[7]/div")
# ActionChains(driver).move_to_element(element14).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 成本分析-车辆成本计算-车辆列表
# element15 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[7]/div")
# ActionChains(driver).move_to_element(element15).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 成本分析-车辆成本规划-车辆列表
# element16 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[7]/div")
# ActionChains(driver).move_to_element(element16).perform()
# time.sleep(5)
# driver.find_element_by_class_name("ant-menu-title-content").click()
# time.sleep(1)
#
# # 创新-创新报告-车辆列表
# element17 = driver.find_element(By.XPATH,"/html/body/div[1]/div/header/section/ul/li[8]/div")
# ActionChains(driver).move_to_element(element17).perform()
# time.sleep(5)
# # element = driver.find_element(By.XPATH,"/html/body/div[8]/div/div/ul/li/ul/li")
# # ActionChains(driver).double_click(element).perform()
# # time.sleep(1)

# 退出Darwin系统
driver.quit()
